package com.ruoyi.jxsx.service.impl;

import java.util.List;

import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.jxsx.util.CourseStatusUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.jxsx.mapper.JxsxTrainingMapper;
import com.ruoyi.jxsx.domain.JxsxTraining;
import com.ruoyi.jxsx.service.IJxsxTrainingService;
import com.ruoyi.common.core.text.Convert;

/**
 * 模拟实训Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-14
 */
@Service
public class JxsxTrainingServiceImpl implements IJxsxTrainingService 
{
    @Autowired
    private JxsxTrainingMapper jxsxTrainingMapper;

    /**
     * 查询模拟实训
     * 
     * @param trainingId 模拟实训主键
     * @return 模拟实训
     */
    @Override
    public JxsxTraining selectJxsxTrainingByTrainingId(String trainingId)
    {
        return jxsxTrainingMapper.selectJxsxTrainingByTrainingId(trainingId);
    }

    /**
     * 查询模拟实训列表
     * 
     * @param jxsxTraining 模拟实训
     * @return 模拟实训
     */
    @Override
    public List<JxsxTraining> selectJxsxTrainingList(JxsxTraining jxsxTraining)
    {
        List<JxsxTraining> jxsxTrainingList = jxsxTrainingMapper.selectJxsxTrainingList(jxsxTraining);
        if(!jxsxTrainingList.isEmpty()){
            jxsxTrainingList.forEach(item->{
                item.setSTATUS(CourseStatusUtil.getCourseStatus(item.getStartTime(), item.getEndTime())+"");
            });
        }
        return jxsxTrainingList;
    }

    /**
     * 新增模拟实训
     * 
     * @param jxsxTraining 模拟实训
     * @return 结果
     */
    @Override
    public int insertJxsxTraining(JxsxTraining jxsxTraining)
    {
        jxsxTraining.setTrainingId(IdUtils.fastSimpleUUID());
        jxsxTraining.setCreateBy(ShiroUtils.getLoginName());
        jxsxTraining.setPublisher(ShiroUtils.getUserId().toString());
        jxsxTraining.setTeachingMode("0");
        jxsxTraining.setSTATUS(CourseStatusUtil.getCourseStatus(jxsxTraining.getStartTime(), jxsxTraining.getEndTime())+"");
        return jxsxTrainingMapper.insertJxsxTraining(jxsxTraining);
    }

    /**
     * 修改模拟实训
     * 
     * @param jxsxTraining 模拟实训
     * @return 结果
     */
    @Override
    public int updateJxsxTraining(JxsxTraining jxsxTraining)
    {
        jxsxTraining.setSTATUS(CourseStatusUtil.getCourseStatus(jxsxTraining.getStartTime(), jxsxTraining.getEndTime())+"");
        return jxsxTrainingMapper.updateJxsxTraining(jxsxTraining);
    }

    /**
     * 批量删除模拟实训
     * 
     * @param trainingIds 需要删除的模拟实训主键
     * @return 结果
     */
    @Override
    public int deleteJxsxTrainingByTrainingIds(String trainingIds)
    {
        return jxsxTrainingMapper.deleteJxsxTrainingByTrainingIds(Convert.toStrArray(trainingIds));
    }

    /**
     * 删除模拟实训信息
     * 
     * @param trainingId 模拟实训主键
     * @return 结果
     */
    @Override
    public int deleteJxsxTrainingByTrainingId(String trainingId)
    {
        return jxsxTrainingMapper.deleteJxsxTrainingByTrainingId(trainingId);
    }
}
